<%@ page import="org.jeecgframework.web.util.StaticValue" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
 <div region="center" style="padding:1px;">
  <t:datagrid name="cbsDelinerList" checkbox="true" fitColumns="false" title="发货管理" actionUrl="cbsDelinerController.do?userCSADatagridTodo"  idField="id" fit="true" queryMode="group" onLoadSuccess="changeColor">
   <t:dgCol title="主键"  field="id"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="发货单号"  field="code"   queryMode="single" query="true"  width="120"></t:dgCol>
   <t:dgCol title="发货状态"  field="status"    queryMode="single"  width="100"   dictionary="<%= StaticValue.Deliver_State %>" query="true"></t:dgCol>
   <t:dgCol title="发货单类型"  field="deliverType"    queryMode="single" query="true" dictionary="<%= StaticValue.Deliver_Type %>" width="85" ></t:dgCol>
   <t:dgCol title="SO"  field="soCode"    queryMode="single"  width="90" query="true"></t:dgCol>
   <t:dgCol title="影院名称"  field="cinemaName"  query="true"  queryMode="single"  width="120" ></t:dgCol>
   <t:dgCol title="所属省市"  field="territoryName" hidden="true"  query="true"  queryMode="single"  width="120" ></t:dgCol>
   <t:dgCol title="省"  field="shengName"   queryMode="single"  width="120" ></t:dgCol>
   <t:dgCol title="市"  field="shiName"   queryMode="single"  width="120" ></t:dgCol>
   <t:dgCol title="备件申请单号"  field="recordId"    queryMode="single" query="true" width="120"></t:dgCol>
   <t:dgCol title="CR"  field="crCode"    queryMode="single" query="true" width="120" ></t:dgCol>
   <t:dgCol title="备件类型"  field="typeDesc"    queryMode="single"  width="120"></t:dgCol>
   <%--<t:dgCol title="备件号"  field="item"    queryMode="single"  width="120"></t:dgCol>--%>
   <t:dgCol title="CSA发货人"  field="CSAName"  query="true" hidden="true" queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="数量"  field="total"    queryMode="single"  width="120"></t:dgCol>
   <%--<t:dgCol title="申请优先级"  field="applyLayer"  dictionary="<%= StaticValue.apply_layer %>"  queryMode="single"  width="120"></t:dgCol>--%>
   <t:dgCol title="发货SLA"  field="fhSLA"    queryMode="single"  query="true" dictionary="<%= StaticValue.Deliver_SLA %>"  width="120" ></t:dgCol>
   <t:dgCol title="物流"  field="deliverLogistics"  query="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="物流承诺SLA"  field="wlSLA"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="SLA未达标"  field="isStandard"    queryMode="single" query="true" dictionary="<%= StaticValue.Deliver_Standard %>"  width="120"></t:dgCol>
   <t:dgCol title="ETA延迟"  field="etaStandard"    queryMode="single" query="true" dictionary="<%= StaticValue.ETA_STANDARD %>"  width="120"></t:dgCol>
   <t:dgCol title="签收延迟"  field="signStandard"    queryMode="single" query="true" dictionary="<%= StaticValue.SIGN_STANDARD %>"  width="120"></t:dgCol>
   <t:dgCol title="创单时间"  field="createDate" query="true"  queryMode="group"  width="120" ></t:dgCol>
   <t:dgCol title="CSA发货时间"  field="CSASendTime"   query="true"  queryMode="group"  width="120"></t:dgCol>
   <t:dgCol title="物流发货时间"  field="logisticsSendTime"    queryMode="group" query="true"  width="120"></t:dgCol>
   <t:dgCol title="预计到货时间"  field="expectTime"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="签收时间"  field="getTime"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="物流时长"  field="logisticsDuration"    queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="物流单号"  field="logNumber" query="true"   queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="创建人名称"  field="createName"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="姓名"  field="userName"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="收货人电话"  field="phone"  query="true"  queryMode="single"  width="100"></t:dgCol>
      <t:dgCol title="SR"  field="srCode"   queryMode="single"  width="75" query="true"></t:dgCol>
   <t:dgCol title="详细地址"  field="address"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="电影院名称"  field="cinemaName"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备件序列号SN"  field="sn"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="创建人登录名称"  field="createBy"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="更新人名称"  field="updateName"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="更新人登录名称"  field="updateBy"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="更新日期"  field="updateDate" formatter="yyyy-MM-dd" hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <%--<t:dgCol title="操作" field="opt" width="100"></t:dgCol>
   <t:dgDelOpt title="删除" url="cbsDelinerController.do?doDel&id={id}" />--%>
   <t:dgToolBar title="发货" icon="icon-add"  funname="CSAadd"></t:dgToolBar>
   <t:dgToolBar title="编辑" icon="icon-add"  funname="addNewTab"></t:dgToolBar>
   <t:dgToolBar title="查看" icon="icon-search"  funname="addDetailsTab"></t:dgToolBar>
   <t:dgToolBar title="新建发货单" icon="icon-add"  funname="addCreateTab"></t:dgToolBar>
   <%--<t:dgToolBar title="批量删除"  icon="icon-remove"  funname="deleteALLSelect"></t:dgToolBar>--%>
   <t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>
  </t:datagrid>
 </div>
</div>
<script src = "webpage/com/zybk/cbs_deliver/cbsDelinerList.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        //给时间控件加上样式
        $("#cbsDelinerListtb").find("input[name='createDate_begin']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
        $("#cbsDelinerListtb").find("input[name='createDate_end']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
        $("#cbsDelinerListtb").find("input[name='updateDate']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
        $("#cbsDelinerListtb").find("input[name='CSASendTime_begin']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
        $("#cbsDelinerListtb").find("input[name='CSASendTime_end']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
        $("#cbsDelinerListtb").find("input[name='logisticsSendTime_begin']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
        $("#cbsDelinerListtb").find("input[name='logisticsSendTime_end']").attr("class","Wdate").attr("style","height:20px;width:90px;").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});

        territoryLink("cbsDelinerList","territoryName");
    });
    function CSAadd() {
        var datas = $("#cbsDelinerList").datagrid("getSelections");
        if(datas.length == 1){
            var id = datas[0].id;
            var code = datas[0].code;
            var status=datas[0].status;
            if(status=='4'){
                tip("该发货单已欠货");
            }else{
                addOneTab('CSA发货'+code, 'cbsDelinerController.do?CSADeliner&id='+id, '');
            }
        }else if (datas.length==0){
            tip("请选择您要发货的发货单");
            return false;
        }else {
            sendTogether();
        }

    }
    function sendTogether() {

        var ids = [];
        var datas = $("#cbsDelinerList").datagrid("getSelections");
        var tempDatas =[];
        var zts = [];
        var users = [];
        var phones = [];
        var addresses=[];
        var statuses = [];
        var deliverTypes = [];
        var isdeliverType = true;
        var isStaus=true;
        var isAddress = true;
        var isPhone = true;
        var isUser =true;
        var isTrue = true;
        var isZt = true;
        if (datas.length>1){
            for ( var i = 0; i < datas.length; i++) {
                tempDatas.push(datas[i].crCode);
                ids.push(datas[i].id);
                zts.push(datas[i].zt);
                users.push(datas[i].userName);
                phones.push(datas[i].phone);
                deliverTypes.push(datas[i].deliverType);
                addresses.push(datas[i].address);
                statuses.push(datas[i].status);
            }
            var sendIds = ids.toString();
            sendIds=decodeURI(sendIds);
            for (var i=0;i<tempDatas.length;i++){
                if(tempDatas.indexOf(tempDatas[i])!=0){
                    isTrue = false;
                    break;
                }
            }
            for (var i=0;i<zts.length;i++){
                if(zts.indexOf(zts[i])!=0){
                    isZt = false;
                    break;
                }
            }
            for (var i=0;i<users.length;i++){
                if(users.indexOf(users[i])!=0){
                    isUser = false;
                    break;
                }
            }
            for (var i=0;i<phones.length;i++){
                if(phones.indexOf(phones[i])!=0){
                    isPhone = false;
                    break;
                }
            }
            for (var i=0;i<deliverTypes.length;i++){
                if(deliverTypes.indexOf(deliverTypes[i])!=0){
                    isdeliverType = false;
                    break;
                }
            }
            for (var i=0;i<addresses.length;i++){
                if(addresses.indexOf(addresses[i])!=0){
                    isAddress = false;
                    break;
                }
            }
            for (var i=0;i<statuses.length;i++){
                if(statuses.indexOf(statuses[i])!=0){
                    isStaus = false;
                    break;
                }else{
                    if(statuses[0]!=1 && statuses[0]!=4){
                        tip("请检查发货单的状态是否均为“CSA待发货”或“欠货中”");
                        return false;
                    }
                }
            }
            if (isTrue==false){
                tip("请检查CR是否一致");
                return false;
            }else if(isZt==false){
                tip("请检查自提是否一致");
                return false;
            }else if(isUser==false){
                tip("请检查收货人姓名是否一致");
                return false;
            }else if(isAddress==false){
                tip("请检查收货地址是否一致");
                return false;
            }else if(isStaus==false){
                tip("请检查发货单状态是否一致");
                return false;
            }else if(isdeliverType==false){
                tip("请检查发货单类型是否一致");
                return false;
            }
            var code = datas[0].code;
            $.dialog.confirm('确定要合并发货吗?', function(r) {
                if(r){

                    addOneTab('CSA合并发货', 'cbsDelinerController.do?sendTogether&ids='+ids, '');

                }
            });
        }

    }
    function addCreateTab() {
        addOneTab('新建发货单', 'cbsDelinerController.do?goAdd', '');
    }

    function addNewTab(){
        var datas = $("#cbsDelinerList").datagrid("getSelections");
        if(datas.length != 1){
            tip("请选择一条发货单");
            return;
        }
        var id = datas[0].id;
        var sn = datas[0].sn;
        var code = datas[0].code;
        var status=datas[0].status;
        if(status==7 || status==3){
            addOneTab("发货单详情"+code,"cbsDelinerController.do?goDeliverDetails&id="+id+"&sn="+sn,"");
        }else{
            addOneTab("编辑"+code,"cbsDelinerController.do?goUpdate&id="+id+"&sn="+sn,"");
        }
    }
    /*
    * 查看发货单
    * */
    function addDetailsTab(){
        var datas = $("#cbsDelinerList").datagrid("getSelections");
        if(datas.length != 1){
            tip("请选择一条发货单");
            return;
        }
        var id = datas[0].id;
        var sn = datas[0].sn;
        var code = datas[0].code;
        addOneTab("发货单详情"+code,"cbsDelinerController.do?goDeliverDetails&id="+id+"&sn="+sn,"");
    }
    function addSearchTab(){
        var datas = $("#cbsDelinerList").datagrid("getSelections");
        if(datas.length != 1){
            tip("请选择一条发货单");
            return;
        }
        var id = datas[0].id;
        var sn = datas[0].sn;
        var code = datas[0].code;
        addOneTab("编辑"+code,"cbsDelinerController.do?goUpdate&id="+id+"&sn="+sn,"");
    }

    function deleteALLSelect(){
        var datas = $("#cbsDelinerList").datagrid("getSelections");
        var ids=[];
        if(datas.length < 1){
            tip("请选择一条或多条发货单");
            return;
        }else{
            for(var i=0;i<datas.length;i++){
                ids.push(datas[i].id)
            }
            $.messager.confirm('确认信息','确定要删除吗?',function(event){
                if(event){
                    //alert("批量删除")
                    console.log("ids:"+ids)
                    $.ajax({
                        type:"POST",
                        data:{'ids':JSON.stringify(ids)},
                        url:"cbsDelinerController.do?deleteALLSelect",
                        dataType:"json",
                        success:function (data) {
                            tip("删除成功");
                            setTimeout(" window.location.href='cbsDelinerController.do?cbsDeliner'",1000);

                        }
                    })
                }else{
                    // alert("你点击的是false");
                }
            }).panel('move',{
                top:100
            })

        }

    }


    //导入
    function ImportXls() {
        openuploadwin('Excel导入', 'cbsDelinerController.do?upload', "cbsDelinerList");
    }

    //导出
    /* function ExportXls() {
         JeecgExcelExport("cbsDelinerController.do?exportXls","cbsDelinerList");
     }*/

    //导出
    function ExportXls() {
        var currPageRows = $("#cbsDelinerList").datagrid("getRows");
        var idsData = [];
        $(currPageRows).each(function (i, rowData) {
            idsData.push(rowData.id);
        });
        if (idsData.length > 0) {
            myDownload("cbsDelinerController.do?exportXls1", "deliverIds=" + idsData.join(","));
        } else {
            tip("当前页面没有数据可以导出");
        }
    }

    //模板下载
    function ExportXlsByT() {
        JeecgExcelExport("cbsDelinerController.do?exportXlsByT","cbsDelinerList");
    }
    function changeColor() {
        var trs = $("#cbsDelinerList").prev().find('div.datagrid-body').find('tr');
        for (var i = 0; i < trs.length; i++) {

            for (var j = 0; j < 20; j++) {

                if (trs[i].cells[j].firstChild.innerHTML =='Y' ){
                    trs[i].cells[j].style.cssText = 'color:red';
                }
            }
        }
    }
</script>